package de.ubschmidt.capi;

import java.nio.ByteBuffer;

/**
 *
 */
public class ConnectB3Resp
        extends CapiActiveMessage
        implements NcciProperty {

    /** The NCCI. */
    private int _ncci;

    /**
     * Create a new {@code ConnectB3Resp} message with the specified NCCI.
     *
     * @param ncci The NCCI.
     */
    public ConnectB3Resp(final int ncci) {
        super(Command.CONNECT_B3_RESP);
        setNcci(ncci);
    }

    /**
     * Create a new {@code ConnectB3Resp} message with the NCCI taken from the
     * specified {@code ConnectB3Ind} message.
     *
     * @see #ConnectB3Resp(int ncci)
     * @param connectB3Ind The {@code ConnectB3Ind} which contains a valid NCCI.
     */
    public ConnectB3Resp(final ConnectB3Ind connectB3Ind) {
        this(connectB3Ind.getNcci());
    }

    /** {@inheritDoc} */
    public int getNcci() {
        return _ncci;
    }

    /** {@inheritDoc} */
    public void setNcci(final int ncci) {
        _ncci = ncci;
    }

    /** {@inheritDoc} */
    protected void serializeTo(final ByteBuffer byteBuffer) {
        byteBuffer.putInt(_ncci);
        byteBuffer.putShort((short) 0);
        byteBuffer.put((byte) 0);
    }

    /** {@inheritDoc} */
    @Override
    public String toString() {
        String s = String.format(
                "%s[%s ncci=0x%08x reject=%s ncpi=%s]",
                getClass().getSimpleName(),
                super.toString(),
                getNcci(),
                0,
                null);

        return s;
    }

}
